<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.fick.hibernate.model.*"%>
<%@ page import="com.fick.hibernate.dao.*"%>
<%@ include file="../tld/tlds.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>河南省公安厅</title>
<link href="images/jiahao.css" rel="stylesheet" type="text/css">

		<link href="css/css.css" rel="stylesheet" type="text/css" />
		<script language="JavaScript" src="js/meihuaxue.js"></script>
		<script language="javaScript" src="js/prototype.js"></script>
		<script type="text/javascript" src="js/submit.js"></script>
		
</head>

<body>
<%
String type=request.getParameter("type");
String typeStr="文字";
if(type!=null && type.equals("2"))
	typeStr="图片";
if(type!=null && type.equals("3"))
	typeStr="下拉";
if(type!=null && type.equals("4"))
	typeStr="视频";
		    String hql = " where isPic='"+type+"'";
		    LinkDAO linkDao = new LinkDAO();
		    Link link = new Link();
		    //当前页面
			int currPage = 1;
			//总的页数
			int totalPage = 1;
			//一个页面可显示的记录数
			int pageSize = 10;
			//总共有的记录数
			int totalCount = 1;
			List  li = new ArrayList();
			//li = linkDao.findAll();
			//得到总的记录数
			totalCount = linkDao.count(Link.class,hql);
			//得到总的页数
			if(totalCount%pageSize==0){
				totalPage = totalCount/pageSize;
			}else{
				totalPage = totalCount/pageSize+1;
			}
			//判断是否是传过来页数
			if(request.getParameter("currPage") != null){
			   currPage = Integer.parseInt(request.getParameter("currPage"));
			   if(currPage<1){
			     currPage=1;
			    }
			   if(currPage >totalPage){
			     currPage = totalPage;
			   }
			} 
			//得到记录数
			  List li2=null;
			  if(type.equals("3"))
			  {
			  	li2 = linkDao.findPageByHql(hql+" order by linkOrder",currPage,pageSize);
			  }else{
			  	li2 = linkDao.findPageByHql(hql+" order by linkClass.className,linkOrder",currPage,pageSize);
			  	}
		 %>

<table width="100%"  height="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="100%" align="center" valign="top" background="images/main_bj.gif" bgcolor="#FBFCFD"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="23" align="left" valign="middle" background="images/main_top.gif"><table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="20" height="23">&nbsp;</td>
            <td width="400" height="23" align="left" valign="middle" class="ts_lmdh2"><%=typeStr %>链接管理 </td>
          </tr>
        </table></td>
      </tr>
    </table>
      <table width="98%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="20" align="left"><input type="button" value="添加<%=typeStr %>链接" onclick="window.location.href='addLink.jsp?type=<%=type %>'"></td>
        </tr>
      </table>
      <table width="98%" border="0" cellpadding="0" cellspacing="1" bgcolor="#D7DFE1">
        <tr>
		 <td width="6%" height="25" align="center" valign="middle" background="images/main_t_bj.gif" bgcolor="#FFFFFF" class="ts_lmdh">选择</td>
          <td width="20%" height="25" align="center" valign="middle" background="images/main_t_bj.gif" bgcolor="#FFFFFF" class="ts_lmdh">分类</td>
          <td width="20%" height="25" align="center" valign="middle" background="images/main_t_bj.gif" bgcolor="#FFFFFF" class="ts_lmdh">网址名</td>
  
          <td width="20%" height="25" align="center" valign="middle" background="images/main_t_bj.gif" bgcolor="#FFFFFF" class="ts_lmdh">网址URL</td>
          <%
          if(type!=null && type.equals("2")){
        	  %>
          <td width="20%" height="25" align="center" valign="middle" background="images/main_t_bj.gif" bgcolor="#FFFFFF" class="ts_lmdh">图片</td>
        	  <%
          }
          %>
          <td width="20%" height="25" align="center" valign="middle" background="images/main_t_bj.gif" bgcolor="#FFFFFF" class="ts_lmdh">操作</td>
        
        </tr>
       
	   <%
		for(int i = 0 ; i < li2.size(); i++){
			link = (Link)li2.get(i);
										      
	 %>
	    <tr>
		<td width="6%" height="25" align="center" valign="middle" bgcolor="#FFFFFF">
		<input type="checkbox" name="MyCheckBox" id="MyCheckBox"
													value="<%=link.getLinkid() %>" />
		</td>
          <td  height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
		  <%=link.getLinkClass()==null?"无":link.getLinkClass().getClassName()%>
		  </td>
          <td  height="25" align="left" valign="middle" bgcolor="#FFFFFF" style="padding-left:7px">
		  <%=link.getWebName()%>
		  </td>
          <td  height="25" align="center" valign="middle" bgcolor="#FFFFFF">
		  <%=link.getWebUrl()%>
		  </td>
		  <%
          if(type!=null && type.equals("2")){
        	  %>
          <td width="20%" height="25" align="center" valign="middle" bgcolor="#FFFFFF">
			<img src="/<%=link.getImg() %>" width="50" height="50">
			</td>
        	  <%
          }
          %>
  			<td  height="25" align="center" valign="middle" bgcolor="#FFFFFF">
			<a href="upLink.jsp?linkid=<%=link.getLinkid() %>&type=<%=type %>">修改</a>&nbsp;
			<a href="<%=request.getContextPath()%>/admin/managerLink.do?method=delById&linkid=<%=link.getLinkid() %>&type=<%=type %>" onclick="javascript:return confirm('确实要删除该信息吗?删除后将不可恢复')">删除</a>
			</td>
        </tr>
      <%
	  }
	  %>
	  
	  <tr>
		<td colspan="4" align="left">
		<input type="button" name="selectAlls" id="selectAlls" value="全选" onclick="return selectAll()" />
		<input type="button" name="noSelectAll" id="noSelectAll" value="反选" onclick="return selectOthers();" />
		<input type="button" name="cancelSelects" id="cancelSelects" value="取消选择" onclick="return cancelSelect();" />
		<input type="button" name="delAlls" id="delAlls" value="删除所选" onclick="return delAllLink('<%=type %>');"/>
		</td>
	</tr>
	  
	  </table>
	  
	  
	  
	  
	  
      <table width="98%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="45" align="center" valign="middle">
		  共有［<%=totalCount %>］条 当前是第［<%=currPage %>/<%=totalPage %>］页 [
												<a href="managerLink.jsp?currPage=1&type=<%=type %>" class="page">首页</a>][
												<a href="managerLink.jsp?currPage=<%=currPage-1 %>&type=<%=type %>"
													class="page">上一页</a>][
												<a href="managerLink.jsp?currPage=<%=currPage+1 %>&type=<%=type %>"
													class="page">下一页</a>][
												<a href="managerLink.jsp?currPage=<%=totalPage %>&type=<%=type %>"
													class="page">尾页</a>]
		  到第
		  <select onchange="gopage(this)">
		  <%
				for(int i = 0;i<totalPage ; i++)
				{
					out.print("<option value='managerLink.jsp?currPage="+(i+1)+"&type="+type+"'>"+(i+1)+"</option>");
				}
			%>
		  </select>	
          页</td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
<script language="javascript">
 function gopage(selected)
 {
 	window.open(selected.value,"_self");
 }
 </script>
 <%@include file="inc/msg.jsp"%>